﻿using System.Data.Entity;
using System.Runtime.Remoting.Messaging;


namespace KTD.Web.BaseDataAccessLayer
{
    public class DbContextManager
    {
        private const string DbCallContextHandler = "KTDContext";

        public static T GetCurrentDal<T>() where T : DbContext, new()
        {
            var nContext = CallContext.GetData(DbCallContextHandler + typeof(T).Name) as T;
            if (nContext != null) return nContext;

            nContext = new T();
            CallContext.SetData(DbCallContextHandler + typeof(T).Name, nContext);
            return nContext;

        }
    }
}